package com.liuf.es.service.impl;

import com.liuf.es.domain.Article;
import com.liuf.es.repository.ArticleSearchRepository;
import com.liuf.es.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 测试demo，文章操作
 * @author LIUFANG
 */
@Service
public class ArticleServiceImpl implements IArticleService {

    @Autowired
    private ArticleSearchRepository searchRepository;

    @Override
    public Article save(Article article) {
        Article object = searchRepository.save(article);
        return object;
    }

    @Override
    public Optional<Article> getByID(Long id) {
        return searchRepository.findById(id);
    }

    @Override
    public Page<Article> queryAll(Article article) {
        Pageable pageable = new PageRequest(0, 50);
        return searchRepository.findAll(pageable);
    }
}
